home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.09 Sep 88 / 4d stuff / Source Files / AreaButton.p next >
Encoding:
Text File  |  1988-06-23  |  1.6 KB  |  75 lines  |  [TEXT/MPS ]

  1. Program Ext_AreaButton;
  2.  
  3. Uses MemTypes, QuickDraw, OSIntf,
  4.             ToolIntf, PackIntf;
  5.  
  6. Const
  7.     InitEvt=16;
  8.     DeInitEvt=17;
  9.  
  10. Type
  11.     {This is the definition of the data}
  12.     {structure I want to use.  All I want}
  13.     {to know is if the Mouse was clicked}
  14.     {in the external area.  0 if NO,}
  15.     {1 if YES.}
  16.     MyData =     record
  17.                                  Status:Integer;
  18.                                 end;
  19.     MyDataPtr = ^ MyData;
  20.     MyDataHndl = ^MyDataPtr;
  21.  
  22. Var
  23.     AreaEv:EventRecord;
  24.     AreaRec:Rect;
  25.     AreaNam:str255;
  26.     AreaHnd:MyDataHndl;
  27.  
  28. procedure AreaButton(
  29.     var AreaEvent:EventRecord;
  30.     var AreaRect:Rect;
  31.     var AreaName:str255;
  32.     var AreaHndl:MyDataHndl);
  33.  
  34. var tPoint:Point;    {Tracks the mouse location.}
  35.  
  36. begin
  37.     Case AreaEvent.What of
  38.         InitEvt:
  39.             begin
  40.                 {Create a new handle for our}
  41.                 {structure.}
  42.                 AreaHndl:=MyDataHndl(NewHandle(
  43.                         sizeof(MyData)));
  44.                 {Initialize the setting to 0. Not}
  45.                 {clicked.}
  46.                 AreaHndl^^.Status:=0;
  47.             end;    {InitEvt}
  48.         MouseDown:
  49.             begin
  50.                 {Wait for mouse up so we know they}
  51.                 {completed the click within our}
  52.                 {area and didn't drag out of the}
  53.                 {area before releasing.}
  54.                 While StillDown do begin end;
  55.                 {Is the mouse in our area?}
  56.                 GetMouse(tPoint);
  57.                 {AreaRect is our rect so test if the}
  58.                 {point is in our area.}
  59.                 if(PtInRect(tPoint, AreaRect)) then
  60.                     {They clicked in our area so}
  61.                     {Status=1.  Clicked}
  62.                     AreaHndl^^.Status:=1;
  63.             end;    {MouseDown}
  64.         DeInitEvt:
  65.             begin    {Get rid of our handle}
  66.                 DisposHandle(Handle(AreaHndl));
  67.             end;    {DeInitEvt}
  68.     end;    {Case AreaEvent.What}
  69. end;    {AreaButton}
  70.  
  71. Begin
  72.     AreaButton(AreaEv, AreaRec, AreaNam,
  73.         AreaHnd);
  74. End.        {Main Block}
  75.